package liurong.driver.sync;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class CustomSyncUtil<T> {
	private CountDownLatch countDownLatch = new CountDownLatch(1);

	private T response;

	public void setRespose(T response) {
		this.response = response;
		countDownLatch.countDown();
	}

	public T getResponse(long timeout, TimeUnit unit) throws Exception {
		if (countDownLatch.await(timeout, unit)) {
			return response;
		} else {
			return null;
		}
	}
}
